﻿using AdverseEventReportSystem.BLL;
using AdverseEventReportSystem.BLL.ServiceReference1;
using AdverseEventReportSystem.Core;
using AdverseEventReportSystem.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AdverseEventReportSystem.Web.Areas.Sysbase
{
    public class PositionController : BaseController
    {
        // GET: Sysbase/Position
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 职称列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Search()
        {
            string typeId = WebUtils.GetString("typeId");
            string title = WebUtils.GetString("title");
            string code = WebUtils.GetString("code");
            FunctionAndPermissionsSoapClient service = new FunctionAndPermissionsSoapClient();
            ResultHelperOfDataTable serviceResult = service.getPositionlist(title, code, typeId);
            DataTable dt = new DataTable();
            if (serviceResult.S)
            {
                dt = serviceResult.D;
            }

            var result = new { Rows = dt };
            return JsonDate(result);
        }

        /// <summary>
        /// 添加/编辑
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(int id = 0)
        {
            tb_Position position = new tb_Position();
            if (id > 0)
            {
                FunctionAndPermissionsSoapClient service = new FunctionAndPermissionsSoapClient();
                ResultHelperOftb_Position result = service.GetPosition(id);
                if (result.S)
                {
                    position = result.D;
                }
            }
            ViewBag.Position = position;
            return View();
        }

        /// <summary>
        /// 添加/编辑职称
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Save(tb_Position position)
        {
            OperateResult resultInfo = PositionManager.Save(position);
            return JsonDate(resultInfo);
        }

        /// <summary>
        /// 删除职称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Delete(int id)
        {
            OperateResult resultInfo = PositionManager.Delete(id);
            return JsonDate(resultInfo);
        }
    }
}